package com.company3;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class poker {
    public static void main(String[] args) {
        // 获取扑克
        poker.getCards();
        // 洗牌
        poker.shuffle();
        // 发牌
        poker.distribute();
        // 显示牌
        poker.showCards();
    }
    //生成大小
    private static String[] value = { "大王", "小王", "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3" };
    //生成花色
    private static String[] type = { "红桃", "黑桃", "梅花", "方块" };
    //存放扑克牌
    private static Map<Integer, String> cards = new HashMap<>();
    //用于打乱牌
    private static List<Integer> order = new ArrayList<>();
    //玩家a的牌
    private static List<Integer> playera = new ArrayList<>();
    //玩家b的牌
    private static List<Integer> playerb = new ArrayList<>();
    //玩家c的牌
    private static List<Integer> playerc = new ArrayList<>();
    //底牌
    private static List<Integer> x = new ArrayList<>();
    //生成扑克牌
    public static void getCards() {
        //初始化牌数
        int index = 1;
        //遍历赋值牌号
        for (int i = 0; i < value.length; i++) {
            for (String s : type) {
                if (i < 2) {//大小王没有花色
                    cards.put(index, value[i]);
                    order.add(index);
                    index++;
                    break;
                } else {//给大小王赋值
                    cards.put(index, s + value[i]);
                    order.add(index);
                    index++;
                }
            }
        }
    }
    //洗牌
    public static void shuffle(){
        Collections.shuffle(order);
    }
    //发牌
    public static void distribute(){
        //遍历牌号发牌
        for (int i = 0; i < order.size(); i++) {
            int cardId = order.get(i);
            if(i<3){//如果剩3张就为底牌
                x.add(cardId);
            }
            //通过除3余数发牌
            else if (i%3==1) {
                playera.add(cardId);
            }else if(i%3==2){
                playerb.add(cardId);
            }else{
                playerc.add(cardId);
            }
        }
        //排序
        Collections.sort(playera);
        Collections.sort(playerb);
        Collections.sort(playerc);
    }
    //展示
    public static void showCards(){
        System.out.println("a玩家：");
        printCards(playera);
        System.out.println("\nb玩家：");
        printCards(playerb);
        System.out.println("\nc玩家：");
        printCards(playerc);
        System.out.println("\n底牌：");
        printCards(x);
    }
    //打印
    private static void printCards(List<Integer> l){
        //通过遍历取牌
        for (Integer integer : l) {
            System.out.print(cards.get(integer)+" ");
        }
    }
}
